from math import sqrt

class Vector:

  # x,y,z
  c = []
  
  # ----------------------------------------------------------------------------
  def __init__(self, _c=[0,0,0]): self.c = _c
  def __str__(self): return str(self.c)    

  def Clear(self): self.__init__()

  # ----------------------------------------------------------------------------
  # ==, !=
  def __eq__(self, v): return self.c == v.c
  def __ne__(self, v): return self.c != v.c

  # ----------------------------------------------------------------------------
  # -(v)
  def __neg__(self): return Vector([-(a) for a in self.c])
  
  # ----------------------------------------------------------------------------  
  # +,+=
  def __add__(self, v): return Vector([a+b for a,b in zip(self.c, v.c)])
  def __iadd__(self, v):
    self.c = [a+b for a,b in zip(self.c, v.c)]
    return self

  # ----------------------------------------------------------------------------
  # -,-=
  def __sub__(self, v): return Vector([a-b for a,b in zip(self.c, v.c)])
  def __isub__(self, v):
    self.c = [a-b for a,b in zip(self.c, v.c)]
    return self

  # ----------------------------------------------------------------------------
  # *,*=
  def __mul__(self, k): return Vector([a*k for a in self.c])
  
  def __rmul__(self, k): return (self * k)
  def __imul__(self, k):
    self.c = [a*k for a in self.c]
    return self

  # ----------------------------------------------------------------------------
  # /,/=
  def __div__(self, k):
    try:
      return Vector([a/k for a in self.c])
    except ZeroDivisionError:
      return Vector()
  
  def __rdiv__(self, k): return (self / k)
  def __idiv__(self, k):
    try:
      self.c = [a/k for a in self.c]
    except ZeroDivisionError: pass
    return self

  # ----------------------------------------------------------------------------    
  def Magnitude(self): return sqrt(sum([a ** 2 for a in self.c])) 
  def Unitize(self):
    magnitude = self.Magnitude()
    try:
      self.c = [a/magnitude for a in self.c]  
    except ZeroDivisionError: pass

  def ScalarProduct(self, v):
      x,y,z = self.c      
      vx,vy,vz = v.c
      return (x*vx + y*vy + z*vz)

  def VectorProduct(self, v):
      x,y,z = self.c      
      vx,vy,vz = v.c
      return Vector([  y * vz - z * vy,
                     -(x * vz - z * vx),
                       x * vy - y * vx  ]) 
